<script>
function delay(ms) {
  return new Promise((resolve, reject) => {
    setTimeout(resolve, ms)
  })
}

const p1 = delay(1000).then(() => 'p1')
const p2 = delay(2000).then(() => 'p2')
const p3 = delay(500).then(() => Promise.reject())
const begin = Date.now()
Promise.race([p1, p2, p3, 1]).then(
  v => {
    console.log('成功：', v, Date.now() - begin)
  },
  v => {
    console.log('失败：', v, Date.now() - begin)
  }
)

</script>

